﻿using Microsoft.AspNet.SignalR.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var connection = new HubConnection("http://localhost:55968/");
            var myHub = connection.CreateHubProxy("ChatHub");

            connection.Start().ContinueWith(task =>
                                                {
                                                    if (task.IsFaulted)
                                                    {
                                                        Console.WriteLine("There was an error opening the connection:{0}",
                                                                          task.Exception.GetBaseException());
                                                    }
                                                    else
                                                    {
                                                        Console.WriteLine("Connected");
                                                    }

                                                }).Wait();

            myHub.Invoke<string>("Register", "New User").ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error calling send: {0}",
                                      task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine(task.Result);
                }
            });

            myHub.Invoke<string>("Register", "AAA").ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error calling send: {0}",
                                      task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine(task.Result);
                }
            });

            myHub.Invoke<string>("Register", "Buba").ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error calling send: {0}",
                                      task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine(task.Result);
                }
            });


            //myHub.On<string>("addMessage", param =>
            //                                {
            //                                    Console.WriteLine(param);
            //                                });

            myHub.On("hello", () => { Console.WriteLine("Buba!"); });

            Console.Read();
            connection.Stop();
        }
    }
}
